<?php
class Member_reg extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		// 登录校验
		$this->common->check_login_mobile ();
		$this->load->helper ( array (
				'form',
				'url' 
		) );
	}

	/**
	 * 注册会员
	 */
	public function index() {
		$this->load->model ( 'user_model' );
		$result = $this->user_model->get_user_info_id ( $_SESSION ['mobile'] ['id'] );
		$data ['up_account'] = $result ['user_account'];
        $data ['pid'] = $result ['id'];
		$data ['left'] = $this->load->view ( 'mobile/left', '', TRUE );
		$data ['foot'] = $this->load->view ( 'mobile/foot', '', TRUE );
		$this->load->view ( 'mobile/member_reg', $data, FALSE );
	}

	/**
	 * 注册会员
	 */
	public function member_insert() {
		if ($_SESSION ['code'] != $_POST ['yzm']) {
			exit ( $this->common->alert_msg_goback ( '验证码错误' ) );
		}

		if ($_POST ['pwd'] !== $_POST ['pwd2'] || $_POST ['spwd'] !== $_POST ['spwd2']) {
			exit ( $this->common->alert_msg_goback ( '注册失败，二次密码不符。' ) );
		}

		if (empty ( $_POST ['user_account'] ) || empty ( $_POST ['pwd'] ) || empty ( $_POST ['spwd'] ) || empty ( $_POST ['user_name'] ) || empty ( $_POST ['mobile'] ) || empty ( $_POST ['zfb_account'] )) {
			exit ( $this->common->alert_msg_goback ( '注册失败，内容不全。' ) );
		}

		$this->load->model ( 'user_model' );
		$result = $this->user_model->user_insert ();

		if ($result) {
			exit ( $this->common->alert_msg_url ( '注册成功', site_url ( 'mobile/my_member' ) ) );
		} else {
			exit ( $this->common->alert_msg_goback ( '注册失败' ) );
		}
	}
}